package com.qipay.baas.mapper;

import static org.apache.ibatis.jdbc.SqlBuilder.BEGIN;
import static org.apache.ibatis.jdbc.SqlBuilder.INSERT_INTO;
import static org.apache.ibatis.jdbc.SqlBuilder.SET;
import static org.apache.ibatis.jdbc.SqlBuilder.SQL;
import static org.apache.ibatis.jdbc.SqlBuilder.UPDATE;
import static org.apache.ibatis.jdbc.SqlBuilder.VALUES;
import static org.apache.ibatis.jdbc.SqlBuilder.WHERE;

import com.qipay.baas.model.Cp;

public class CpSqlProvider {

    public String insertSelective(Cp record) {
        BEGIN();
        INSERT_INTO("cp");
        
        if (record.getType() != null) {
            VALUES("`type`", "#{type,jdbcType=TINYINT}");
        }
        
        if (record.getAppId() != null) {
            VALUES("app_id", "#{appId,jdbcType=CHAR}");
        }
        
        if (record.getSecretId() != null) {
            VALUES("secret_id", "#{secretId,jdbcType=CHAR}");
        }
        
        if (record.getAgentId() != null) {
            VALUES("agent_id", "#{agentId,jdbcType=BIGINT}");
        }
        
        if (record.getFeeDefaultRecharge() != null) {
            VALUES("fee_default_recharge", "#{feeDefaultRecharge,jdbcType=DECIMAL}");
        }
        
        if (record.getCostWithdraw() != null) {
            VALUES("cost_withdraw", "#{costWithdraw,jdbcType=INTEGER}");
        }
        
        if (record.getFeeWithdrawAdvince() != null) {
            VALUES("fee_withdraw_advince", "#{feeWithdrawAdvince,jdbcType=DECIMAL}");
        }
        
        if (record.getWithdrawPassword() != null) {
            VALUES("withdraw_password", "#{withdrawPassword,jdbcType=VARCHAR}");
        }
        
        if (record.getNotifyUrl() != null) {
            VALUES("notify_url", "#{notifyUrl,jdbcType=VARCHAR}");
        }
        
        if (record.getIp() != null) {
            VALUES("ip", "#{ip,jdbcType=VARCHAR}");
        }
        
        if (record.getBindMobile() != null) {
            VALUES("bind_mobile", "#{bindMobile,jdbcType=VARCHAR}");
        }
        
        if (record.getCreateTime() != null) {
            VALUES("create_time", "#{createTime,jdbcType=TIMESTAMP}");
        }
        
        if (record.getAccountState() != null) {
            VALUES("account_state", "#{accountState,jdbcType=TINYINT}");
        }
        
        if (record.getContractState() != null) {
            VALUES("contract_state", "#{contractState,jdbcType=TINYINT}");
        }
        
        return SQL();
    }

    public String updateByPrimaryKeySelective(Cp record) {
        BEGIN();
        UPDATE("cp");
        
        if (record.getType() != null) {
            SET("`type` = #{type,jdbcType=TINYINT}");
        }
        
        if (record.getAppId() != null) {
            SET("app_id = #{appId,jdbcType=CHAR}");
        }
        
        if (record.getSecretId() != null) {
            SET("secret_id = #{secretId,jdbcType=CHAR}");
        }
        
        if (record.getAgentId() != null) {
            SET("agent_id = #{agentId,jdbcType=BIGINT}");
        }
        
        if (record.getFeeDefaultRecharge() != null) {
            SET("fee_default_recharge = #{feeDefaultRecharge,jdbcType=DECIMAL}");
        }
        
        if (record.getCostWithdraw() != null) {
            SET("cost_withdraw = #{costWithdraw,jdbcType=INTEGER}");
        }
        
        if (record.getFeeWithdrawAdvince() != null) {
            SET("fee_withdraw_advince = #{feeWithdrawAdvince,jdbcType=DECIMAL}");
        }
        
        if (record.getWithdrawPassword() != null) {
            SET("withdraw_password = #{withdrawPassword,jdbcType=VARCHAR}");
        }
        
        if (record.getNotifyUrl() != null) {
            SET("notify_url = #{notifyUrl,jdbcType=VARCHAR}");
        }
        
        if (record.getIp() != null) {
            SET("ip = #{ip,jdbcType=VARCHAR}");
        }
        
        if (record.getBindMobile() != null) {
            SET("bind_mobile = #{bindMobile,jdbcType=VARCHAR}");
        }
        
        if (record.getCreateTime() != null) {
            SET("create_time = #{createTime,jdbcType=TIMESTAMP}");
        }
        
        if (record.getAccountState() != null) {
            SET("account_state = #{accountState,jdbcType=TINYINT}");
        }
        
        if (record.getContractState() != null) {
            SET("contract_state = #{contractState,jdbcType=TINYINT}");
        }
        
        WHERE("id = #{id,jdbcType=BIGINT}");
        
        return SQL();
    }
}